﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using model;
using dao;

namespace business
{
    public class BaivietBUS
    {
        LoaibaivietDao loaiBaivietDao = new LoaibaivietDao();
        BaivietDao baivietDao = new BaivietDao();

        public List<Baiviet> getAllBaiviet()
        {
            return baivietDao.getAllBaiviet();
        }

        public List<Baiviet> getBaivietTop1ByLoai()
        {
            List<Baiviet> glsBaiviet = new List<Baiviet>();
            List<Loaibaiviet> glsLoaibaiviet = new List<Loaibaiviet>();
            glsLoaibaiviet = loaiBaivietDao.GetListAllLoaiBaiviet();
            foreach (Loaibaiviet l in glsLoaibaiviet)
            {
                List<Baiviet> glsBv = new List<Baiviet>();
                glsBv = baivietDao.getBaivietTop1ByLoai(l.ID);
                if (glsBv.Count > 0)
                {
                    Baiviet bv = glsBv[0];
                    bv.Header = getTenloaibaiviet(l.Maloaibai);
                    glsBaiviet.Add(bv);
                }
                
            }
            return glsBaiviet;
        }

        private string getTenloaibaiviet(string s)
        {
            switch (s)
            { 
                case "L1":
                    return "Trà";
                case "L2":
                    return "Trà cụ";
                case "L3":
                    return "Trà thất";
                case "L4":
                    return "Nghệ thuật thưởng trà";
                case "L5":
                    return "Văn hóa trà việt";
                case "L6":
                    return "Tản mạn";
            }
            return "";
        }
        public List<Baiviet> getBaivietTop3ByLoai(long id)
        {
            List<Baiviet> glsBaiviet = new List<Baiviet>();
            List<Baiviet> glsBaivietResult = new List<Baiviet>();
            Baiviet baiViet = new Baiviet();
            baiViet = baivietDao.getBaivietByID(id);
            glsBaiviet = baivietDao.getTop3BaivietByLoai(baiViet.IDLoaibaiviet);
            if (glsBaiviet.Count > 0)
                glsBaiviet.RemoveAt(0);
            if (glsBaiviet.Count >= 2)
            {
                glsBaivietResult.Add(glsBaiviet[0]);
                glsBaivietResult.Add(glsBaiviet[1]);
            }
            else if (glsBaiviet.Count >= 1)
            {
                glsBaivietResult.Add(glsBaiviet[0]);
            }
            return glsBaivietResult;
        }

        public List<Baiviet> getListBaivietByLoai(long id)
        {
            return baivietDao.getBaivietByLoai(id);
        }
    }
}
